# Import the Python API Client
import pyeodhhttps://github.com/cedadev/stac-notebooks/blob/main/stac-api-example.ipynb
# Connect to the Hub
client = pyeodh.Client().get_catalog_service()
# Print a list of the collections held in the Resource Catalogue (their id and description).
# As the Resource Catalogue fills and development continues, the number of collections and the richness of their descriptions will increase
for collect in client.get_collections():
print(f"- {collect.id}: {collect.description}")- cmip6: CMIP6
- cordex: CORDEX
- ukcp: UKCP
- airbus_sar_data: The German TerraSAR-X / TanDEM-X satellite formation and the Spanish PAZ satellite (managed by Hisdesat Servicios Estratégicos S.A.) are being operated in the same orbit tube and feature identical ground swaths and imaging modes - allowing Airbus and Hisdesat to establish a unique commercial Radar Constellation. The satellites carry a high frequency X-band Synthetic Aperture Radar (SAR) sensor in order to acquire datasets ranging from very high-resolution imagery to wide area coverage.
- defra-airbus: A collection of Airbus data for the DEFRA use case.
- defra-planet: A collection of Planet data for the DEFRA use case.
- eocis-sst-cdrv3: EOCIS Sea-Surface Temperatures V3
- sentinel2_ard: sentinel 2 ARD
- sentinel1: Sentinel 1
- naip: The [National Agriculture Imagery Program](https://www.fsa.usda.gov/programs-and-services/aerial-photography/imagery-programs/naip-imagery/) (NAIP) provides U.S.-wide, high-resolution aerial imagery, with four spectral bands (R, G, B, IR). NAIP is administered by the [Aerial Field Photography Office](https://www.fsa.usda.gov/programs-and-services/aerial-photography/) (AFPO) within the [US Department of Agriculture](https://www.usda.gov/) (USDA). Data are captured at least once every three years for each state. This dataset represents NAIP data from 2010-present, in [cloud-optimized GeoTIFF](https://www.cogeo.org/) format.
cmip6 = client.get_catalog("supported-datasets/ceda-stac-catalogue").get_collection('cmip6')
cmip6.extent.to_dict()
item_search = client.search(
collections=['cmip6'],
query=[
'start_datetime<=2023-01-01',
'end_datetime>=2023-02-28',
'experiment_id=ssp585',
],
limit=10,
)item_search<pyeodh.pagination.PaginatedList at 0x7dd003ff1400>
# chatty
# https://radiantearth.github.io/stac-browser/#/external/test.eodatahub.org.uk/api/catalogue/stac/catalogs/supported-datasets/ceda-stac-catalogue/collections/cmip6/items/CMIP6.ScenarioMIP.CSIRO-ARCCSS.ACCESS-CM2.ssp126.r1i1p1f1.day.pr.gn.v20210317?.asset=asset-data0001
import xarray as xr
import matplotlib.pyplot as plt
import numpy as np
# Path to the NetCDF file (replace with your file path)
file_path = "/home/al/Downloads/pr_day_ACCESS-CM2_ssp126_r1i1p1f1_gn_22510101-23001231.nc"
# Open the NetCDF file using xarray
data = xr.open_dataset(file_path)
# Display the dataset summary
data/home/al/miniforge3/envs/eodh/lib/python3.12/site-packages/xarray/coding/times.py:987: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range
dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime)
/home/al/miniforge3/envs/eodh/lib/python3.12/site-packages/xarray/coding/times.py:987: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range
dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime)
/home/al/miniforge3/envs/eodh/lib/python3.12/site-packages/xarray/core/indexing.py:524: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range
return np.asarray(self.get_duck_array(), dtype=dtype)
<xarray.Dataset> Size: 2GB
Dimensions: (time: 18262, bnds: 2, lat: 144, lon: 192)
Coordinates:
* time (time) object 146kB 2251-01-01 12:00:00 ... 2300-12-31 12:00:00
* lat (lat) float64 1kB -89.38 -88.12 -86.88 ... 86.88 88.12 89.38
* lon (lon) float64 2kB 0.9375 2.812 4.688 6.562 ... 355.3 357.2 359.1
Dimensions without coordinates: bnds
Data variables:
time_bnds (time, bnds) object 292kB ...
lat_bnds (lat, bnds) float64 2kB ...
lon_bnds (lon, bnds) float64 3kB ...
pr (time, lat, lon) float32 2GB ...
Attributes: (12/47)
Conventions: CF-1.7 CMIP-6.2
activity_id: ScenarioMIP
branch_method: standard
branch_time_in_child: 60265.0
branch_time_in_parent: 60265.0
creation_date: 2021-03-17T01:55:47Z
... ...
variable_id: pr
variant_label: r1i1p1f1
version: v20210317
license: CMIP6 model data produced by CSIRO is licensed un...
cmor_version: 3.4.0
tracking_id: hdl:21.14100/d0f83bdc-dad3-41e5-9bcc-84c8c1cd099c
#To plot the first time step
data.pr.isel(time=0).plot()

#Clip
data2 = data.isel(time=slice(0, 50))import geoviews as gv
#import geoviews.feature as gf
import xarray as xr
from cartopy import crs
gv.extension('bokeh', 'matplotlib')
#(gf.ocean + gf.land + gf.ocean * gf.land * gf.coastline * gf.borders).opts(
# 'Feature', projection=crs.Geostationary(), global_extent=True, height=325)
dataset = gv.Dataset(data2)
ensemble = dataset.to(gv.Image, ['lon', 'lat'], 'pr')
gv.output(ensemble.opts(cmap='viridis', colorbar=True, fig_size=120, backend='matplotlib') * gf.coastline(),
backend='matplotlib',
max_frames=200)
# # Close the dataset to free resources
data.close()